package com.lanxiaoye.shoppingSystem.service.impl;

import com.lanxiaoye.shoppingSystem.dao.*;
import com.lanxiaoye.shoppingSystem.entity.*;
import com.lanxiaoye.shoppingSystem.service.ModuleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Administrator on 2017/3/22.
 */
@Service
public class ModuleServiceImpl implements ModuleService{

    @Autowired
    SuggestionMapper suggestionMapper;

    @Autowired
    ReceiptInfoMapper receiptInfoMapper;

    @Autowired
    CategoryMapper categoryMapper;

    @Autowired
    ScanRecordMapper scanRecordMapper;

    @Autowired
    CommentMapper commentMapper;

    @Autowired
    ShoppingCarMapper shoppingCarMapper;

    @Autowired
    UserOrderMapper userOrderMapper;

    @Override
    public int addSuggestion(Suggestion suggestion) {
        return suggestionMapper.insertSelective(suggestion);
    }

    @Override
    public List<ReceiptInfo> getReceiptInfo(int user_id) {
        return receiptInfoMapper.selectByUserId(user_id);
    }

    @Override
    public int deleteReceiptInfo(int id) {
        return receiptInfoMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int addReceiptInfo(ReceiptInfo receiptInfo) {
        return receiptInfoMapper.insertSelective(receiptInfo);
    }

    @Override
    public List<Category> getAllCategory() {
        return categoryMapper.selectAll();
    }

    @Override
    public List<ScanRecord> getRecentScan(int userId) {
        return scanRecordMapper.selectRecentScan(userId);
    }

    @Override
    public List<Comment> getGoodsComment(int goodsId) {
        return commentMapper.selectByGoodsId(goodsId);
    }

    @Override
    public int addScanRecord(ScanRecord scanRecord) {
        return scanRecordMapper.insertSelective(scanRecord);
    }

    @Override
    public int updateScanRecord(ScanRecord scanRecord) {
        return scanRecordMapper.updateByPrimaryKeySelective(scanRecord);
    }

    @Override
    public ScanRecord getRecordByUserAndGoods(int userId, int goodsId) {
        return scanRecordMapper.selectByUserAndGoods(userId,goodsId);
    }

    @Override
    public ShoppingCar getCartByUserAndGoods(int userId, int goodsId) {
        return shoppingCarMapper.selectByUserAndGoods(userId,goodsId);
    }

    @Override
    public int updateShoppingCart(ShoppingCar shoppingCar) {
        return shoppingCarMapper.updateByPrimaryKeySelective(shoppingCar);
    }

    @Override
    public int addShoppingCart(ShoppingCar shoppingCar) {
        return shoppingCarMapper.insertSelective(shoppingCar);
    }

    @Override
    public List<ShoppingCar> getCartsByUserId(int userId) {
        return shoppingCarMapper.selectByUserId(userId);
    }

    @Override
    public int deleteShoppingCart(int id) {
        return shoppingCarMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int addOrder(UserOrder userOrder) {
        return userOrderMapper.insertSelective(userOrder);
    }

    @Override
    public int deleteCartByUserId(int userId) {
        return shoppingCarMapper.deleteByUserId(userId);
    }

    @Override
    public int cancelOrder(int userId) {
        return userOrderMapper.updateStatusToCancel(userId);
    }

    @Override
    public int payOrder(int userId) {
        return userOrderMapper.updateStatusToPay(userId);
    }

    @Override
    public List<UserOrder> getOrderByUserId(int userId) {
        return userOrderMapper.selectByUserId(userId);
    }

    @Override
    public UserOrder getOrderByOrderId(int orderId) {
        return userOrderMapper.selectByPrimaryKey(orderId);
    }

    @Override
    public int addComment(Comment comment) {
        return commentMapper.insertSelective(comment);
    }

    @Override
    public Comment getCommentByOrderId(int orderId) {
        return commentMapper.selectByOrderId(orderId);
    }
}
